const STATUS = {
  0: '未支付',
  1: '已支付'
}
import axios from '@/utils/request'
export default {
  Purchase: {
    list: {
      query: {
        '@expands': `['entity.relatedOrder']`,
        '@order': `entity.createdTime|DESC`
      },
      list_filter: {
        'fromStore.id': () => { 
          return axios
            .get(`/manage/stores`)
            .then(res =>
              Object.assign({ __label: '申购门店' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
        'toStore.id': () => {
          return axios
            .get(`/manage/stores`)
            .then(res =>
              Object.assign({ __label: '采购门店' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        }
      },
      // disabled_actions: ['lines'],
      list_display: [
        'id',
        {
          property: 'fromStore',
          label: '申购门店'
        },
        {
          property: 'toStore',
          label: '采购门店'
        },
        {
          property: 'items',
          label: '采购内容',
          component: {
            props: ['data'],
            data() {
              return {
                purchaseItems: []
              }
            },
            render(h) {
              return <div style='width: 500px'>
                <el-table
                  data={this.data}
                  style='width: 500px'>
                  <el-table-column
                    prop='__metadata.specification.__toString'
                    label='产品'
                    width='250px'>
                  </el-table-column>
                  <el-table-column
                    prop='__metadata.quantity'
                    label='采购数量'>
                  </el-table-column>
                  <el-table-column
                    prop='__metadata.retrieved'
                    label='已入库'>
                  </el-table-column>
                  <el-table-column
                    prop='__metadata.primeCost'
                    label='采购单价'>
                  </el-table-column>
                </el-table>
              </div>
            }
          }
        },
        {
          property: 'relatedOrder',
          label: '对应销售单',
          component: {
            props: ['data'],
            render(h) {
              if (this.data != null) {
                return <div>
                  <div>{STATUS[this.data.__metadata.status]}</div>
                </div>
              } else {
                return <div>无</div>
              }
            }
          }
        },
        'createdTime',
        'comment'
      ]
    },
    form: {
      fields: [
        'fromStore',
        'toStore',
        'user',
        // 'status',
        // 'items',
        'description'
      ]
    }
  }
}

